<%#-- copyright
OpenProject is an open source project management software.
Copyright (C) 2012-2020 the OpenProject GmbH

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3.

OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
Copyright (C) 2006-2017 Jean-Philippe Lang
Copyright (C) 2010-2013 the ChiliProject Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

See docs/COPYRIGHT.rdoc for more details.

++#%>

<%# we have to assign the cost_object here as following methods depend on the item having an object -%>
<% template_object = @cost_object.labor_budget_items.build.tap do |i|
  i.cost_object = @cost_object
end -%>

<costs-budget-subform item-count="<%= @cost_object.labor_budget_items.length %>"
                      update-url="<%= url_for(action: :update_labor_budget_item, project_id: @project.id) %>">
  <fieldset id="labor_budget_items_fieldset" class="form--fieldset -collapsible">
    <legend class="form--fieldset-legend"><%= VariableCostObject.human_attribute_name(:labor_budget) %></legend>
    <div class="generic-table--container">
      <div class="generic-table--results-container">
        <table class="generic-table" id="labor_budget_items">
          <colgroup>
            <col highlight-col>
            <col highlight-col>
            <col highlight-col>
            <% if User.current.allowed_to?(:view_cost_rates, @project)%>
              <col highlight-col>
            <%end%>
            <col>
          </colgroup>
          <thead>
            <tr>
              <th class="cost_units">
                <div class="generic-table--sort-header-outer">
                  <div class="generic-table--sort-header">
                    <span>
                      <%= LaborBudgetItem.human_attribute_name(:hours) %>
                    </span>
                  </div>
                </div>
              </th>
              <th>
                <div class="generic-table--sort-header-outer">
                  <div class="generic-table--sort-header">
                    <span>
                      <%= LaborBudgetItem.human_attribute_name(:user) %>
                    </span>
                  </div>
                </div>
              </th>
              <th>
                <div class="generic-table--sort-header-outer">
                  <div class="generic-table--sort-header">
                    <span>
                      <%= LaborBudgetItem.human_attribute_name(:comment) %>
                    </span>
                  </div>
                </div>
              </th>
              <% if User.current.allowed_to?(:view_cost_rates, @project)%>
                <th class="currency" id="labor_budget_items_price">
                  <div class="generic-table--sort-header-outer">
                    <div class="generic-table--sort-header">
                      <span>
                        <%= LaborBudgetItem.human_attribute_name(:budget) %>
                      </span>
                    </div>
                  </div>
                </th>
              <%end%>
              <th></th>
            </tr>
          </thead>
          <tbody id="labor_budget_items_body" class="budget-item-container">
            <%= render partial: "cost_objects/items/labor_budget_item", object: template_object, locals: { templated: true } %>
            <%- @cost_object.labor_budget_items.each_with_index do |labor_budget_item, index| -%>
              <%= render partial: 'cost_objects/items/labor_budget_item', object: labor_budget_item, locals: {index: index} %>
            <%- end -%>
          </tbody>
        </table>

      </div>
    </div>
    <div class="wp-inline-create-button">
      <a href="#" class="budget-add-row wp-inline-create--add-link" role="link" title="<%= t(:button_add_budget_item) %>">
        <%= op_icon('icon icon-add') %>
      </a>
    </div>
  </fieldset>
</costs-budget-subform>
